from time import sleep
import pytest
from selenium import webdriver
data = [('11112222', '123456', '8888', '账号格式不匹配!'),
          ('13012345678', '123456', '8888', '安全退出')]
class TestCase:
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get('http://hmshop-test.itheima.net/Home/user/login.html')
    def teardown(self):
        sleep(1)
        self.driver.quit()
    @pytest.mark.parametrize("username, password, verify_code, expect", data)
    def test_login(self, username, password, verify_code, expect):
        self.driver.find_element_by_id("username").send_keys(username)
        self.driver.find_element_by_name("password").send_keys(password)
        self.driver.find_element_by_id("verify_code").send_keys(verify_code)
        self.driver.find_element_by_xpath("//*[@id='loginform']/div/div[6]/a").click()
        if expect == '账号格式不匹配！':
            information_tip = self.driver.find_element_by_class_name\
                                                ("//*[@id='layui-layer1']/div[2]/i").text
            assert expect == information_tip
        elif expect == '安全退出':
            safe_exit = self.driver.find_element_by_partial_link_text("安全退出").text
            assert expect == safe_exit
        else:
            print("请输入正确的账号格式")
